package com.tm.d6_math;

/**
 *2024/5/23 Cjj Math常见方法 18：37
 */
public class MathTest {
    public static void main(String[] args) {
       //目标：了解Math提供的常见方法

       //1.取绝对值(结果一定是正数)
        System.out.println(Math.abs(-12));
        System.out.println(Math.abs(5));
        System.out.println(Math.abs(-14));

        //2.public static double ceil(double a)向上取整
        System.out.println(Math.ceil(18.4));//19
        System.out.println(Math.ceil(19.5));//20
        System.out.println(Math.ceil(1));//1

        //3.public static double floor(double a)向下取整
        System.out.println(Math.floor(18.4));//18
        System.out.println(Math.floor(19.5));//19
        System.out.println(Math.ceil(1));//1

        //4.public static long round(double a)四舍五入
        System.out.println(Math.round(15.3));//15
        System.out.println(Math.round(24.5));//25

        //5.public static int max(int a,int b)取较大值
        //public   static int min(int a,int b)取较小值
        System.out.println(Math.max(5, 6));//6
        System.out.println(Math.max(78, 36));//78
        System.out.println(Math.min(4, 6));//4

        //6.public static double pow(double a,double b)取次方
        System.out.println(Math.pow(4, 2));//16
        System.out.println(Math.pow(3, 4));//81
        System.out.println(Math.pow(2, 3));//8

        //7.public static double random()//随机数[0.0,1.0](包前不包后)
        System.out.println(Math.random());


    }
}
